package com.lostreseditores.sabersai.dataaccess.dao;

import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.Query;
import org.hibernate.Session;
import org.hibernate.criterion.Example;

import com.lostreseditores.sabersai.dataaccess.sessionFactory.HibernateSessionFactory;
import com.lostreseditores.sabersai.model.Respuestaxasignatura;


public class RespuestaxasignaturaDAO implements IRespuestaxasignaturaDAO {
    private static final Log log = LogFactory.getLog(RespuestaxasignaturaDAO.class);

    // property constants
    //public static final Integer  RESPXASIGACTIVON = "respxasigactivon";
    public static final String RESPXASIGACTIVON = "respxasigactivon";

    //public static final String  RESPXASIGCORRECV = "respxasigcorrecv";
    public static final String RESPXASIGCORRECV = "respxasigcorrecv";

    //public static final Integer  RESPXASIGDIFN = "respxasigdifn";
    public static final String RESPXASIGDIFN = "respxasigdifn";

    //public static final Integer  RESPXASIGIDN = "respxasigidn";
    public static final String RESPXASIGIDN = "respxasigidn";

    //public static final String  RESPXASIGNIVDESV = "respxasignivdesv";
    public static final String RESPXASIGNIVDESV = "respxasignivdesv";

    //public static final String  RESPXASIGNIVELDESV = "respxasigniveldesv";
    public static final String RESPXASIGNIVELDESV = "respxasigniveldesv";

    //public static final Integer  RESPXASIGOPAN = "respxasigopan";
    public static final String RESPXASIGOPAN = "respxasigopan";

    //public static final Integer  RESPXASIGOPBN = "respxasigopbn";
    public static final String RESPXASIGOPBN = "respxasigopbn";

    //public static final Integer  RESPXASIGOPCN = "respxasigopcn";
    public static final String RESPXASIGOPCN = "respxasigopcn";

    //public static final Integer  RESPXASIGOPDN = "respxasigopdn";
    public static final String RESPXASIGOPDN = "respxasigopdn";

    //public static final Integer  RESPXASIGORDENN = "respxasigordenn";
    public static final String RESPXASIGORDENN = "respxasigordenn";

    //public static final Integer  RESPXASIGPREGESPN = "respxasigpregespn";
    public static final String RESPXASIGPREGESPN = "respxasigpregespn";

    //public static final Integer  RESPXASIGTXTN = "respxasigtxtn";
    public static final String RESPXASIGTXTN = "respxasigtxtn";

    private Session getSession() {
        return HibernateSessionFactory.getSession();
    }

    /**
    *
    * @param Instance
    *            Respuestaxasignatura Instance to persist
    * @throws RuntimeException
    *             when the operation fails
    */
    public void save(Respuestaxasignatura instance) {
        log.debug("saving Respuestaxasignatura instance");

        try {
            getSession().save(instance);
            log.debug("save successful");
        } catch (RuntimeException re) {
            log.error("save failed", re);
            throw re;
        }
    }

    /**
    * @param Instance
    *            Respuestaxasignatura Instance to delete
    * @throws RuntimeException
    *             when the operation fails
    */
    public void delete(Respuestaxasignatura instance) {
        log.debug("deleting Respuestaxasignatura instance");

        try {
            getSession().delete(instance);
            log.debug("delete successful");
        } catch (RuntimeException re) {
            log.error("delete failed", re);
            throw re;
        }
    }

    /**
    *
    * @param Instance
    *            Respuestaxasignatura Instance to update
    * @throws RuntimeException
    *             when the operation fails
    */
    public void update(Respuestaxasignatura instance) {
        log.debug("updating Respuestaxasignatura instance");

        try {
            getSession().update(instance);
            log.debug("update successful");
        } catch (RuntimeException re) {
            log.error("update failed", re);
            throw re;
        }
    }

    public Respuestaxasignatura findById(Integer id) {
        log.debug("finding Respuestaxasignatura instance with id: " + id);

        try {
            Respuestaxasignatura instance = (Respuestaxasignatura) getSession()
                                                                       .get(Respuestaxasignatura.class,
                    id);

            return instance;
        } catch (RuntimeException re) {
            log.error("finding Respuestaxasignatura failed", re);
            throw re;
        }
    }

    public List<Respuestaxasignatura> findByExample(
        Respuestaxasignatura instance) {
        log.debug("finding Respuestaxasignatura instance by example");

        try {
            List results = getSession().createCriteria("Respuestaxasignatura")
                               .add(Example.create(instance)).list();
            log.debug("find by example successful, result size: " +
                results.size());

            return results;
        } catch (RuntimeException re) {
            log.error("find by example failed", re);
            throw re;
        }
    }

    /**
    * Find all  Respuestaxasignatura entities with a specific property value.
    *
    * @param value
    *            the property value to match
    * @param propertyName
    *            the property to search in the instance
    * @return List< Respuestaxasignatura> found by query
        */
    public List<Respuestaxasignatura> findByProperty(String propertyName,
        Object value) {
        log.debug("finding Respuestaxasignatura instance with property: " +
            propertyName + ", value: " + value);

        try {
            String queryString = "from Respuestaxasignatura as model where model." +
                propertyName + "= ?";
            Query queryObject = getSession().createQuery(queryString);
            queryObject.setParameter(0, value);

            return queryObject.list();
        } catch (RuntimeException re) {
            log.error("find by property name failed", re);
            throw re;
        }
    }

    public List<Respuestaxasignatura> findByRespxasigactivon(
        Object respxasigactivon) {
        return findByProperty(RESPXASIGACTIVON, respxasigactivon);
    }

    public List<Respuestaxasignatura> findByRespxasigcorrecv(
        Object respxasigcorrecv) {
        return findByProperty(RESPXASIGCORRECV, respxasigcorrecv);
    }

    public List<Respuestaxasignatura> findByRespxasigdifn(Object respxasigdifn) {
        return findByProperty(RESPXASIGDIFN, respxasigdifn);
    }

    public List<Respuestaxasignatura> findByRespxasigidn(Object respxasigidn) {
        return findByProperty(RESPXASIGIDN, respxasigidn);
    }

    public List<Respuestaxasignatura> findByRespxasignivdesv(
        Object respxasignivdesv) {
        return findByProperty(RESPXASIGNIVDESV, respxasignivdesv);
    }

    public List<Respuestaxasignatura> findByRespxasigniveldesv(
        Object respxasigniveldesv) {
        return findByProperty(RESPXASIGNIVELDESV, respxasigniveldesv);
    }

    public List<Respuestaxasignatura> findByRespxasigopan(Object respxasigopan) {
        return findByProperty(RESPXASIGOPAN, respxasigopan);
    }

    public List<Respuestaxasignatura> findByRespxasigopbn(Object respxasigopbn) {
        return findByProperty(RESPXASIGOPBN, respxasigopbn);
    }

    public List<Respuestaxasignatura> findByRespxasigopcn(Object respxasigopcn) {
        return findByProperty(RESPXASIGOPCN, respxasigopcn);
    }

    public List<Respuestaxasignatura> findByRespxasigopdn(Object respxasigopdn) {
        return findByProperty(RESPXASIGOPDN, respxasigopdn);
    }

    public List<Respuestaxasignatura> findByRespxasigordenn(
        Object respxasigordenn) {
        return findByProperty(RESPXASIGORDENN, respxasigordenn);
    }

    public List<Respuestaxasignatura> findByRespxasigpregespn(
        Object respxasigpregespn) {
        return findByProperty(RESPXASIGPREGESPN, respxasigpregespn);
    }

    public List<Respuestaxasignatura> findByRespxasigtxtn(Object respxasigtxtn) {
        return findByProperty(RESPXASIGTXTN, respxasigtxtn);
    }

    /**
    * Find all Respuestaxasignatura entities.
    *
    * @return List<Respuestaxasignatura> all Respuestaxasignatura instances
    */
    public List<Respuestaxasignatura> findAll() {
        log.debug("finding all Respuestaxasignatura instances");

        try {
            String queryString = "from Respuestaxasignatura";
            Query queryObject = getSession().createQuery(queryString);

            return queryObject.list();
        } catch (RuntimeException re) {
            log.error("find all failed", re);
            throw re;
        }
    }

    public List<Respuestaxasignatura> findByCriteria(String whereCondition) {
        log.debug("finding Respuestaxasignatura " + whereCondition);

        try {
            String where = ((whereCondition == null) ||
                (whereCondition.length() == 0)) ? "" : ("where " +
                whereCondition);
            final String queryString = "select model from Respuestaxasignatura model " +
                where;
            Query query = getSession().createQuery(queryString);
            List<Respuestaxasignatura> entitiesList = query.list();

            return entitiesList;
        } catch (RuntimeException re) {
            log.error("find By Criteria in Respuestaxasignatura failed", re);
            throw re;
        }
    }

    public List<Respuestaxasignatura> findPageRespuestaxasignatura(
        String sortColumnName, boolean sortAscending, int startRow,
        int maxResults) {
        log.debug("finding Respuestaxasignatura findPageRespuestaxasignatura");

        if ((sortColumnName != null) && (sortColumnName.length() > 0)) {
            try {
                String queryString = "select model from Respuestaxasignatura model order by model." +
                    sortColumnName + " " + (sortAscending ? "asc" : "desc");

                return getSession().createQuery(queryString)
                           .setFirstResult(startRow).setMaxResults(maxResults)
                           .list();
            } catch (RuntimeException re) {
                throw re;
            }
        } else {
            try {
                String queryString = "select model from Respuestaxasignatura model";

                return getSession().createQuery(queryString)
                           .setFirstResult(startRow).setMaxResults(maxResults)
                           .list();
            } catch (RuntimeException re) {
                throw re;
            }
        }
    }

    public Long findTotalNumberRespuestaxasignatura() {
        log.debug("finding Respuestaxasignatura count");

        try {
            String queryString = "select count(*) from Respuestaxasignatura model";
            Query queryObject = getSession().createQuery(queryString);

            return (Long) queryObject.list().get(0);
        } catch (RuntimeException re) {
            throw re;
        }
    }
}
